package com.lbw.factory.factorymethod.order;


import com.lbw.factory.factorymethod.pizza.Pizza;
import com.sun.tools.javac.util.Assert;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author lbw
 * @version 1.0
 * @date 2021/9/5 11:41
 */
public abstract class OrderPizza {
    private final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

    abstract Pizza createPizza(String orderType);


    public OrderPizza() {
        Pizza pizza = null;
        String orderType;
        do {
            orderType = getType();
            pizza = createPizza(orderType);
            Assert.checkNonNull(pizza, "非常抱歉, 没有这种披萨");
            // 输出过程
            pizza.prepare();
            pizza.bake();
            pizza.cut();
            pizza.box();
        } while (true);
    }


    private String getType() {

        System.out.println("input pizza type: ");
        String type = null;
        try {
            type = reader.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return type;
    }
}
